﻿//-----------------------------------------------------------------------
// <copyright file="StringUtilities.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>28/01/2013</date>
//-----------------------------------------------------------------------

using System;
using System.Linq;

namespace ConsoleHoster.Common.Utilities
{
	public static class StringUtilities
	{
		public static string Format(string argFormat, params string[] args)
		{
			return String.Format(argFormat, EscapeFormatArgs(args));
		}

		private static string[] EscapeFormatArgs(string[] args)
		{
			string[] tmpResult = null;

			if (args != null)
			{
				tmpResult = args.Select(item => EscapeFormatParameter(item)).ToArray();
			}

			return tmpResult;
		}

		private static string EscapeFormatParameter(string argParameter)
		{
			string tmpResult = argParameter;

			if (tmpResult != null)
			{
				tmpResult = tmpResult.Replace("{", "{{").Replace("}", "}}");
			}

			return tmpResult;
		}
	}
}
